package com.yangwp.doutu.service.impl;

import com.yangwp.doutu.dao.DotuUserDao;
import com.yangwp.doutu.model.DotuUser;
import com.yangwp.doutu.service.DoutuUserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class DoutuUserServiceImpl implements DoutuUserService {

    @Autowired
    private DotuUserDao dotuUserDao;

    @Override
    public Boolean addUser(String userName, String userId, String head){
        DotuUser dotuUser = new DotuUser();
        dotuUser.setUserId(userId);
        dotuUser.setUserName(userName);
        dotuUser.setUserHead(head);
        dotuUser.setCreateTime(new Date());
        return dotuUserDao.insert(dotuUser) > 0;
    }

    @Override
    public Boolean isUserExists(String userId){
        if(StringUtils.isBlank(userId)){
            return Boolean.FALSE;
        }
        try {
            return dotuUserDao.getDotuUserByUserId(userId) != null;
        }catch (Exception e){
            return Boolean.FALSE;
        }
    }
}
